import numpy as np;

# a = np.array([0.3,2.9,4.0])
# exp_a = np.exp(a)
# print("exp_a",exp_a)
#
# sum_exp_a = np.sum(exp_a)
# print(sum_exp_a)
#
# y=exp_a/sum_exp_a
# print("softmax(a):",y)


def softmax(a):
    exp_a = np.exp(a)
    sum_exp_a = np.sum(exp_a)
    y = exp_a / sum_exp_a


a = np.array([1010,1000,990])
a_max = np.max(a)
print("exp_a：",np.exp(a-a_max)/np.sum(np.exp(a-a_max)))
print("softmax(a-a_max):",softmax(a-a_max))

